package sing.rabbit.common.configurations;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author xing
 * @date 2022/9/7 18:58
 */
@Configuration
public class DirectConfiguration {
    public static final String DIRECT_QUEUE_NAME = "direct-queue";
     public static final String DIRECT_EXCHANGE_NAME = "direct-exchange";
     public static final String DIRECT_ROUTING_KEY = "dev";

    @Bean
    public Queue directQueue() {
        return new Queue(DIRECT_QUEUE_NAME, true, false, false);
    }

    @Bean
    public DirectExchange directExchange() {
        return ExchangeBuilder.directExchange(DIRECT_EXCHANGE_NAME).build();
    }

    @Bean
    public Binding binding(Queue directQueue, DirectExchange directExchange) {
        return BindingBuilder
                .bind(directQueue)
                .to(directExchange)
                .with(DIRECT_ROUTING_KEY);
    }

}
